package com.ruoyi.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.mes.domain.MesWorkingHours;
import com.ruoyi.mes.service.IMesWorkingHoursService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工时管理Controller
 * 
 * @author Livon
 * @date 2021-11-09
 */
@RestController
@RequestMapping("/workingHours")
public class MesWorkingHoursController extends BaseController
{
    @Autowired
    private IMesWorkingHoursService mesWorkingHoursService;

    /**
     * 查询工时管理列表
     */
    @PreAuthorize(hasPermi = "mes:workingHours:list")
    @GetMapping("/list")
    public TableDataInfo list(MesWorkingHours mesWorkingHours)
    {
        startPage();
        List<MesWorkingHours> list = mesWorkingHoursService.selectMesWorkingHoursList(mesWorkingHours);
        return getDataTable(list);
    }

    /**
     * 导出工时管理列表
     */
    @PreAuthorize(hasPermi = "mes:workingHours:export")
    @Log(title = "工时管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesWorkingHours mesWorkingHours) throws IOException
    {
        List<MesWorkingHours> list = mesWorkingHoursService.selectMesWorkingHoursList(mesWorkingHours);
        ExcelUtil<MesWorkingHours> util = new ExcelUtil<MesWorkingHours>(MesWorkingHours.class);
        util.exportExcel(response, list, "工时管理数据");
    }

    /**
     * 获取工时管理详细信息
     */
    @PreAuthorize(hasPermi = "mes:workingHours:query")
    @GetMapping(value = "/{workingHoursUuid}")
    public AjaxResult getInfo(@PathVariable("workingHoursUuid") String workingHoursUuid)
    {
        return AjaxResult.success(mesWorkingHoursService.selectMesWorkingHoursByWorkingHoursUuid(workingHoursUuid));
    }

    /**
     * 新增工时管理
     */
    @PreAuthorize(hasPermi = "mes:workingHours:add")
    @Log(title = "工时管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesWorkingHours mesWorkingHours)
    {
        return toAjax(mesWorkingHoursService.insertMesWorkingHours(mesWorkingHours));
    }

    /**
     * 修改工时管理
     */
    @PreAuthorize(hasPermi = "mes:workingHours:edit")
    @Log(title = "工时管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesWorkingHours mesWorkingHours)
    {
        return toAjax(mesWorkingHoursService.updateMesWorkingHours(mesWorkingHours));
    }

    /**
     * 删除工时管理
     */
    @PreAuthorize(hasPermi = "mes:workingHours:remove")
    @Log(title = "工时管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workingHoursUuids}")
    public AjaxResult remove(@PathVariable String[] workingHoursUuids)
    {
        return toAjax(mesWorkingHoursService.deleteMesWorkingHoursByWorkingHoursUuids(workingHoursUuids));
    }
}
